﻿using System;
using System . Collections . Generic;
using System . Collections . ObjectModel;
using System . Linq;
using System . Text;
using System . Threading . Tasks;
using System . Xml . Linq;

namespace GameClassLibrary . Stocks
{
    public class StockMarket : GameObject
    {
        public List<Stock> Stocks { get; private set; } = new List<Stock> ( );

        public StockPriceMovement Movement { get; set; }

        public List<Buffs . StockBuff> Buffs { get; private set; } = new List<Buffs . StockBuff> ( );

        DateTime movement_changing=Game.Current.Date;

        public long SynthesizePrice
        {
            get
            {
                long temp=0;
                foreach ( var item in Stocks )
                {
                    temp += item . Price;
                }
                return temp;
            }
        }

        public override void NextDay ( )
        {
            if ( Game . Current . NextDate == movement_changing )
            {
                switch ( Game . Current . Randomer . Next ( 0 , 3 ) )
                {
                    case 1:
                        {
                            Movement = StockPriceMovement . Rise;
                            break;
                        }
                    case 2:
                        {
                            Movement = StockPriceMovement . Keep;
                            break;
                        }
                    case 3:
                        {
                            Movement = StockPriceMovement . Fall;
                            break;
                        }
                }
                foreach ( var item in Stocks )
                {
                    item . ChangeAnticipate ( );
                }
                movement_changing . AddDays ( Game . Current . Randomer . Next ( 20 , 30 ) );
            }
            foreach ( var item in Stocks )
            {
                item . NextDay ( );
            }
        }

        public StockMarket():base()
        {

        }

        public StockMarket ( XElement saving ) : base ( saving )
        {

        }

        public override XElement Save ( )
        {
            var temp= base . Save ( );

            return temp;
        }
    }
}
